<template>
<div>
	<div class="g_top_box">
		<div class="g_right_box">
			<Button type="primary" @click="add">添加</Button>
		</div> 
		<div class="g_left_box"><h4>多币种管理</h4></div>
	</div>
	
	<div class="g_list_box">
		<div class="g_list_box">
			<Table :columns="Columns" :data="list" style="width: 100%;"></Table>
		</div>
		<div class="g_page_box">
			<Page :total="count" @on-change="goto_page"></Page>
		</div>
	</div>
	<Modal
        v-model="info.show"
        title="详细信息"
        @on-ok="info_ok"
		:width="300"
        >
        <div>
			<Form :label-width="80">
				<FormItem label="名称">
					<Input type="text" v-model="info.info.name" style="width:120px;"></Input>
				</FormItem>
				<FormItem label="汇率">
					<InputNumber :max="100" :min="0" v-model="info.info.exchange_rate" style="width:120px;"></InputNumber>
				</FormItem>
			</Form>
		</div>
	</Modal>
</div>
</template>

<script>

export default {
    name: 'mc_list',
    data () {
		let self = this;
        return {
			Columns: [
				{
					title: '名称',
					key: 'name',
                    width: 220,
					
                },
				{
					title: '汇率',
					key: 'exchange_rate',
                    width: 220,
					
                },
				{
					title: '操作',
					key: 'action',
					render: (h, params) => {
						return h('div', [
							h('Button', {
								props: {
									type: 'primary',
									size: 'small',
									icon:'edit'
								},
								style: {
									marginRight: '5px',
								},
								on: {
									click: () => {
										self.show_info(params.row);
									}
								}
							}, '编辑'),
							h('Button', {
								props: {
									type: 'error',
									size: 'small',
									icon:'trash-a'
								},
								style: {
									display:params.row.username =='admin'?'none':'inline-block'
								},
								on: {
									click: () => {
										this.remove(params.row.id)
									}
								}
							}, '删除')
						]);
					}
				}
            ],
            list: [],
			count:0,
			page:1,
			info:{
				show:false,
				info:{
					name:'',
					exchange_rate:1
				},
				id:0
			}
        };
    },
	components:{
		
	},
	created(){
		this.load_data();
	},
    computed: {
       
    },
	methods:{
		load_data(){
			var self = this;
			
			var postdata = {
				f:this.filter,
				page:this.page
			}
			
			Whttp.load('User/Currency/get_list',postdata,function(result){
				self.list = result.list;
				self.count = parseInt(result.count);
			});
		},
		
		remove(id){
			if(!confirm('是否删除')){
				return;
			}
			var self = this;
			var postdata = {
				id:id
			};
			Whttp.load('User/Currency/del',postdata,function(result){
				self.load_data();
			});
		},
		goto_page(page){
			this.page = page;
			this.load_data();
		},
		add(){
			this.info.id = 0;
			this.info.info = {
				name:'',
				exchange_rate:1
			};
			this.info.show = true;
		},
		info_ok(){
			var self = this;
			
			var postdata = this.info.info;
			
			Whttp.load('User/Currency/save',postdata,function(result){
				self.load_data();
			});
		},
		show_info(val){
			this.info.id = val.id;
			this.info.info = this._getData(val);
			this.info.show = true;
		}
	}
};
</script>
